package development.hdk.mindmapfornandroid;

import java.util.LinkedList;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import development.hdk.tree.*;
import development.hdk.database.BackEnd;

public class MainActivity extends Activity implements OnItemClickListener,OnClickListener {
	public BackEnd be = new BackEnd(this);
	Dialog dialog;
	  String[] icons;
	  ListView lv;
	  LinkedList<String> names;
	  LinkedList<Tree> trees;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/*setContentView(R.layout.activity_main);*/
		setContentView(R.layout.activity_main);
		ListView listView = (ListView) findViewById(R.id.list);
		listView.setOnItemClickListener(this);
	}
	private void createTree()
   {
		AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
	    localBuilder.setTitle("Title of the map:");
	    localBuilder.setIcon(0);
	    EditText localEditText = new EditText(this);
	    localEditText.setInputType(16384);
	    localBuilder.setView(localEditText);
	    //localBuilder.setPositiveButton("Ok", new MindMapActivity$3(this, localEditText));
	    localBuilder.setPositiveButton("OK", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
				
			}
		});
	    localBuilder.setNegativeButton("Cancel", null);
	    this.dialog = localBuilder.create();
	    this.dialog.getWindow().setSoftInputMode(5);
	    this.dialog.setOwnerActivity(this);
	    this.dialog.show();
   }
	private void displayUI()
    {
	    this.trees = this.be.getAllTrees();
	    TreeAdapter localTreeAdapter = new TreeAdapter(getApplicationContext(), 2130903047, this.trees);
	    this.lv.setAdapter(localTreeAdapter);
	    this.lv.setOnItemClickListener(this);
    }
	private void deleteTree(int paramInt)
	{
		this.be.deleteTree(((Tree)this.trees.get(paramInt)).getID());
		displayUI();
	}

	  private void editTree(Tree paramTree)
	  {
	    Intent localIntent = new Intent(this, ProcessorActivity.class);
	    Bundle localBundle = new Bundle();
	    this.be.close();
	    localBundle.putInt("id", paramTree.getID());
	    localBundle.putInt("surfaceColor", paramTree.getSurfaceColor());
	    localIntent.putExtras(localBundle);
	    startActivity(localIntent);
	  }
public void CreateMenu(Menu menu)
	{
		MenuItem item1 = menu.add(0,0,0,"Add");
		{
			item1.setIcon(R.drawable.icon_add);
			item1.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
		}
	}
	private boolean MenuChoice(MenuItem item)
	{
		switch (item.getItemId()) {
		case 0:
			Intent i = new Intent(this, ProcessorActivity.class);
			startActivity(i);
			break;
		default:
			break;
		}
		return true;
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		/*getMenuInflater().inflate(R.menu.main, menu);
		return true;*/
		CreateMenu(menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		/*return super.onOptionsItemSelected(item);*/
		MenuChoice(item);
		return true;
	}
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		//Map map = (Map)arrayList.get(arg2);
		//Toast.makeText(getBaseContext(), map.getMapName(), Toast.LENGTH_SHORT).show();
	}
	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		
	}

}
